package com.cans.strategy;

import org.junit.Test;

/**
 * 计算器
 *
 * @author cans
 * @date 2022/3/26
 **/
public class Calculator {

    /**
     * 计算数字
     *
     * @param num1     参数1
     * @param num2     参数2
     * @param operator 操作算法
     * @return
     */
    public Integer calculate(Integer num1, Integer num2, String operator) {

        if(operator.equals("+")){
            return num1 + num2;
        }else if(operator.equals("-")){
            return num1 - num2;
        }else if(operator.equals("*")){
            return num1 * num2;
        }else if(operator.equals("/")){
            return num1 / num2;
        }
        throw new RuntimeException("无效的操作算法");
    }

    @Test
    public void testCalculate(){

        System.out.println(calculate(1,1,"+"));
    }
}
